package com.translate.web.api.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.param.impl.IdPageParam;
import com.translate.vo.NvitationRewardsConfVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.translate.web.param.NvitationRewardsConfUpdateParam;
import com.translate.web.constant.RedisConstant;
import com.translate.web.param.NvitationRewardsConfAddParam;
import com.translate.entity.NvitationRewardsConf;
import com.translate.web.service.INvitationRewardsConfService;
import com.basic.service.contract.IBaseService;

import java.util.List;

@RestController
@RequestMapping("nvitationRewardsConf")
@Slf4j
public class NvitationRewardsConfController extends AbstractCommonController<NvitationRewardsConf, IdPageParam> {

	@Resource
	private INvitationRewardsConfService service;

	/**
	 * 添加
	 *
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated NvitationRewardsConfAddParam param,
			HttpServletRequest httpServletRequest) {
		int id = this.service.parseInsert(param, NvitationRewardsConf.class);

		return ResponseModel.<Integer>success(id);
	}

	@Override
	protected IBaseService<NvitationRewardsConf> getBaseService() {
		return this.service;
	}

	/**
	 * 添加
	 *
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody NvitationRewardsConfUpdateParam param,
			HttpServletRequest httpServletRequest) {
		int res = this.service.parseUpdate(param, NvitationRewardsConf.class);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) NvitationRewardsConfVO.class;
	}

	/**
	 * 推荐奖励列表
	 * @return
	 */
	@PostMapping("/recommendRewardList")
	public ResponseModel<List<NvitationRewardsConf>> recommendRewardList() {
		
		return ResponseModel.<List<NvitationRewardsConf>>success(this.service.listToCache(RedisConstant.NVITATION_REWARDS_CONF, 100));
		
		
	}
}
